import Vue from 'vue'
import Router from 'vue-router'
Vue.use( Router )
import Layout from '@/layout/BaseLayout/index'
export const constantRoutes = [
  {
    path : '/login',
    name : 'Login',
    component : () => import( '@/views/login/index' ),
    hidden : true
  },
  {
    path : '/auth-redirect',
    component : () => import( '@/views/login/auth-redirect' ),
    hidden : true
  },
  {
    path : '/404',
    component : () => import( '@/views/error-page/404' ),
    hidden : true
  },
  {
    path : '/401',
    component : () => import( '@/views/error-page/401' ),
    hidden : true
  },

  {
    path : '/',
    component : Layout,
    redirect : '/dashboard/index',
    alwaysShow : false,
    hidden : true,
    meta : {
      title : '首页',
      icon : 'my',
      roles : ['admin']
    }
  }
]

export const asyncRoutes = [
  {
    path : '/dashboard',
    component : Layout,
    redirect : '/dashboard/index',
    alwaysShow : false,
    hidden : true,
    meta : {
      title : '首页',
      icon : 'my',
      roles : ['admin', 'user']
    },
    children : [
      {
        path : 'index',
        component : () => import( '@/views/dashboard/index' ),
        name : 'Index',
        hidden : true,
        meta : {
          noCache : true,
          title : '首页',
          roles : ['admin', 'user']
        }
      }
    ]
  },
  {
    path : '/tools',
    component : Layout,
    redirect : '/tools/icons',
    alwaysShow : false,
    meta : {
      title : '工具图标',
      icon : 'my1',
      roles : ['admin']
    },
    children : [
      {
        path : 'icons',
        component : () => import( '@/views/tools/icons' ),
        name : 'Icons',
        meta : {
          noCache : true,
          title : '图标',
          roles : ['admin']
        }
      }
    ]
  },
  
  { path : '*', redirect : '/404', hidden : true }
]
const createRouter = () => new Router( {
  mode : 'history', // require service support
  scrollBehavior : () => {
    history.pushState( null, null, document.URL )
    return ( { y : 0 } )
  },
  routes : constantRoutes
} )

const router = createRouter()
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}
export default router
